﻿using System;

class SurfaceOfATriangle
{
    static void Main()
    {
        //Exercise 4.
        //Write methods that calculate the surface of a triangle by given:
        //  -   Side and an altitude to it; Three sides; Two sides and an angle between them. Use System.Math.

        Console.WriteLine("There are 3 approaches for calculation of the surface of a triangle.");
        Console.WriteLine("1. Side and an altitude to it; \n2. Three sides; \n3. Two sides and an angle between them.");
        Console.Write("Choose one of the opitons: ");
        int choice = int.Parse(Console.ReadLine());
        double surface = 0;
        if (choice == 1)
        {
            surface = SideAndAltitude();
            Console.WriteLine("The surface of the triangle is {0}", surface);
        }
        else if (choice == 2)
        {
            surface = ThreeSides();
            Console.WriteLine("The surface of the triangle is {0}", surface);
        }
        else if (choice == 3)
        {
            surface = TwoSidesAndAngle();
            Console.WriteLine("The surface of the triangle is {0}", surface);
        }
        else
        {
            Console.WriteLine("Invalid choice!");
        }
        Console.WriteLine();
    }

private static double TwoSidesAndAngle()
{
        Console.Write("Enter the length of the first side: ");
        double a = double.Parse(Console.ReadLine());
        Console.Write("Enter the length of the second side: ");
        double b = double.Parse(Console.ReadLine());
        Console.Write("Enter the angle between them in degrees: ");
        int angle = int.Parse(Console.ReadLine());

        double angleInRadians = Math.PI * angle / 180.0;
        double surface = (a * b * Math.Sin(angleInRadians)) / 2;
        return surface;

}

    private static double ThreeSides()
    {
        double surface = 0;
        Console.Write("Enter the length of the first side: ");
        double a = double.Parse(Console.ReadLine());
        Console.Write("Enter the length of the second side: ");
        double b = double.Parse(Console.ReadLine());
        Console.Write("Enter the length of the third side: ");
        double c = double.Parse(Console.ReadLine());
        double p = (a + b + c) / 2;
        
        surface = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
        return surface;
    }

    private static double SideAndAltitude()
    {
        double surface = 0;
        Console.Write("Enter the length of the side: ");
        double a = double.Parse(Console.ReadLine());
        Console.Write("Enter the length of the altitude to the side: ");
        double h = double.Parse(Console.ReadLine());
        surface = (a * h) / 2;
        return surface;
    }
}

